package com.macro.mall.controller;

import com.github.pagehelper.PageInfo;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.e.SysSpiderEntDTO;
import com.macro.mall.dto.o.SysSpiderOutDTO;
import com.macro.mall.service.SysSpiderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/sys/spider")
public class SysSpiderController {
    @Autowired
    private SysSpiderService sysSpiderService;

    @RequestMapping("/list")
    public CommonResult list(@RequestBody SysSpiderEntDTO sysSpiderEntDTO){
        PageInfo<SysSpiderOutDTO> list = sysSpiderService.list(sysSpiderEntDTO);
        return CommonResult.success(list);
    }

    @RequestMapping("/get")
    public CommonResult get(@RequestBody SysSpiderEntDTO sysSpiderEntDTO){
        return null;
    }

    @RequestMapping("/modify")
    public CommonResult modify(@RequestBody SysSpiderEntDTO sysSpiderEntDTO){
        int modify = sysSpiderService.modify(sysSpiderEntDTO);
        CommonResult<Object> commonResult = new CommonResult<>();
        if (modify>0){
            commonResult.setCode(200);
            commonResult.setMessage("操作成功！");
        }else {
            commonResult.setCode(500);
            commonResult.setMessage("操作失败！");
        }
        return commonResult;
    }

    @RequestMapping("/setStatus")
    public CommonResult setStatus(@RequestBody SysSpiderEntDTO sysSpiderEntDTO){
        int modify = sysSpiderService.setStatus(sysSpiderEntDTO);
        CommonResult<Object> commonResult = new CommonResult<>();
        if (modify>0){
            commonResult.setCode(200);
            commonResult.setMessage("操作成功！");
        }else {
            commonResult.setCode(500);
            commonResult.setMessage("操作失败！");
        }
        return commonResult;
    }

    @RequestMapping("/setOff")
    public CommonResult setOff(@RequestBody SysSpiderEntDTO sysSpiderEntDTO){
        return null;
    }
}
